<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #ratio_map="{col,row}">
      <template v-for="(v,rid) in row.ratio_map">
        <el-tag v-if="sharing_receiver_map[rid]">{{sharing_receiver_map[rid]["name"]}}【{{sharing_receiver_map[rid]["pay_type"]}}】：{{v}}%</el-tag>
      </template>
    </template>
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import s94Mjs from "s94-js";
import {ajax} from "@/js/api_tool.js";
import {_config} from "@/js/s94_tool.js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');
    if(in_right_admin('SharingRatio/add')) btns['添加'] = function(){ iframe('sharing_ratio/edit') }
    if(in_right_admin('SharingRatio/delete')) btns['彻底删除'] = function(){ app.$refs['list_url'].delete() }

    var status_config = _config('status_alias_map.sharing_ratio.status');
    let forms_config = {
      link_table: {label:'项目类型',name:'where[link_table][eq]',config:[],type:'select_one',value:''},
    };
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left', type: 'hidden', order:true},
      object_title: {name:'object_title', label:'项目详情', width:'200px', align:'left'},
      ratio_map: {name:'ratio_map', label:'比例详情',type:'ratio_map', min_width:'200px'},
      status: {name:'status', label:'状态', width:'70px',type:'select_one',config:status_config, fixed:'right'},
      action: {name:'action', label:'操作', width:'80px', type:'action', fixed:'right'},
    };

    return {
      config: {
        api: '/admin/sharing_ratio/'+(is_del?'recycle':'list'),
        title: "分账比例列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },
      level_list: [],
      model_map: [],
      sharing_receiver_map: {},
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('SharingRatio/edit') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      let param = {
        link_id: row.link_id,
        link_table: row.link_table || '',
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('sharing_ratio/edit?'+s94Mjs.param_encode(param))
    },
  },
  mounted() {
    let app = this;//667385db93e163789e11bc988a7993a3
    if (!this.__iframe) window['app'] = this;

    ajax({url:'/admin/sharing_ratio/config_map',cache:true},function (res){
      app.sharing_receiver_map = res.data.sharing_receiver_map;
      app.config.forms_config.link_table.config = res.data.link_table_map;
      return false;
    })
  }
}
</script>
